package com.ap.core.webservice.managertp;

import com.ap.core.cxf.jaxb.common.APCORE1FaultDetailsType;
import com.ap.core.cxf.jaxb.managertp.EnquireRTPStatus1Request;
import com.ap.core.cxf.jaxb.managertp.EnquireRTPStatus1Response;
import com.ap.core.cxf.jaxb.managertp.SubmitRTP1Request;
import com.ap.core.cxf.jaxb.managertp.SubmitRTP1Response;
import com.ap.core.exception.BusinessFailureException;
import com.ap.core.message.info.PaymentResponseMessageInfo;
import com.ap.core.message.info.RequestMessageInfo;
import com.ap.core.message.service.CoreResponseInfo;
import com.ap.core.webservice.BaseWSService;
import com.core.ap.wsdl.managertpservice_1.EnquireRTPStatus1Fault;
import com.core.ap.wsdl.managertpservice_1.ManageRTP1PortType;
import com.core.ap.wsdl.managertpservice_1.SubmitRTP1Fault;

import javax.jws.WebParam;

/**
 * Implementation class for {@link ManageRTP1PortType}
 */
public class ManageRTPWebServiceImpl<AI> extends BaseWSService<RequestMessageInfo<?>,PaymentResponseMessageInfo,AI> implements ManageRTP1PortType {


    @Override
    public EnquireRTPStatus1Response enquireRTPStatus1(@WebParam(partName = "enquireRTPStatus_1Request", name = "EnquireRTPStatus_1Request", targetNamespace = "http://ap.core.com/xsd/managertpdata_1") EnquireRTPStatus1Request enquireRTPStatus1Request) throws EnquireRTPStatus1Fault {
        CoreResponseInfo<PaymentResponseMessageInfo, AI> coreResponseInfo = null;
        LOG.info("Starting processing in ap core at time: " + System.currentTimeMillis() + " for message type = " + enquireRTPStatus1Request.getMsgHdr().getMsgType().name());
        try {
            coreResponseInfo = messageProcessor.process(enquireRTPStatus1Request, new EnquireRTPStatus1Response());
        } catch (BusinessFailureException e) {
            final APCORE1FaultDetailsType submitRTP1Fault = buildSOAPFaultType(enquireRTPStatus1Request.getMsgHdr().getMsgType().name(), enquireRTPStatus1Request.getMsgHdr().getMsgId(), e);
            throw new EnquireRTPStatus1Fault(getFaultString(enquireRTPStatus1Request.getMsgHdr().getMsgType().name(), enquireRTPStatus1Request.getMsgHdr().getMsgId()), submitRTP1Fault);
        } catch (Exception e) {
            LOG.error("Runtime exception occurred in  Enquire RTP Status rtp :", e);
            final APCORE1FaultDetailsType submitRTP1Fault = buildSOAPFaultType(enquireRTPStatus1Request.getMsgHdr().getMsgType().name(), enquireRTPStatus1Request.getMsgHdr().getMsgId(),  e);
            throw new  EnquireRTPStatus1Fault(getFaultString(enquireRTPStatus1Request.getMsgHdr().getMsgType().name(), enquireRTPStatus1Request.getMsgHdr().getMsgId()), submitRTP1Fault);
        }
        LOG.info("Finishing processing in ap core at time: " + System.currentTimeMillis() + " for message type = " + enquireRTPStatus1Request.getMsgHdr().getMsgType().name());
        return (EnquireRTPStatus1Response)coreResponseInfo.getResponse();
    }

    @Override
    public SubmitRTP1Response submitRTP1(@WebParam(partName = "submitRTP_1Request", name = "SubmitRTP_1Request", targetNamespace = "http://ap.core.com/xsd/managertpdata_1") SubmitRTP1Request submitRTP1Request) throws SubmitRTP1Fault {
        CoreResponseInfo<PaymentResponseMessageInfo, AI> coreResponseInfo = null;
        LOG.info("Starting processing in ap core at time: " + System.currentTimeMillis() + " for message type = " + submitRTP1Request.getMsgHdr().getMsgType().name());
        try {
            coreResponseInfo = messageProcessor.process(submitRTP1Request, new SubmitRTP1Response());
        } catch (BusinessFailureException e) {
        	final APCORE1FaultDetailsType submitRTP1Fault = buildSOAPFaultType(submitRTP1Request.getMsgHdr().getMsgType().name(), submitRTP1Request.getMsgHdr().getMsgId(), e);
        	throw new SubmitRTP1Fault(getFaultString(submitRTP1Request.getMsgHdr().getMsgType().name(), submitRTP1Request.getMsgHdr().getMsgId()), submitRTP1Fault);            
        } catch (Exception e) {
            LOG.error("Runtime exception occurred in submit rtp :", e);
        	final APCORE1FaultDetailsType submitRTP1Fault = buildSOAPFaultType(submitRTP1Request.getMsgHdr().getMsgType().name(), submitRTP1Request.getMsgHdr().getMsgId(),  e);
            throw new  SubmitRTP1Fault(getFaultString(submitRTP1Request.getMsgHdr().getMsgType().name(), submitRTP1Request.getMsgHdr().getMsgId()), submitRTP1Fault);           
        }
        LOG.info("Finishing processing in ap core at time: " + System.currentTimeMillis() + " for message type = " + submitRTP1Request.getMsgHdr().getMsgType().name());
        return (SubmitRTP1Response)coreResponseInfo.getResponse();
    }


}
